 //
//  MeSettingMainVC.m
//  MPTLive
//
//  Created by caixun on 16/1/29.
//  Copyright © 2016年 Jeakin. All rights reserved.
//

#import "MeSettingMainVC.h"
#import "MeSettingHeadView.h"
#import <MPTLoginApp.h>
#import "AppDelegate.h"
#import "MPTLiveAboutVC.h"
#import "MPTLiveTestViewController.h"

@interface MeSettingMainVC ()<UITableViewDataSource,UITableViewDelegate>


@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) MeSettingHeadView *viewHead;


@end


@implementation MeSettingMainVC


#pragma mark - ********************** View Lifecycle **********************

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self initVariable]; /// 初始化变量
    [self initViews]; /// 初始化界面
    
    [self req_URL_xxx]; /// 发送请求
    
    [self regNotification]; /// 注册消息
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[TPTabBarManager share] showBottomView:NO animation:YES];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)dealloc
{
    // 一定要关注这个函数是否被执行了！！！
}


#pragma mark - ********************** Init All Views **********************

- (void)initVariable
{
    
}

- (void)initViews
{
    [self initNavView]; /// 初始化Nav导航栏
    
    /// 根据界面情况，决定是单独写函数，或直接写Views
    [self initMainViews];
}

- (void)initNavView
{
    /// 创建导航栏
    [self createNavBarViewWithTitle:@"设置"];
    self.superNavBarView.backgroundColor = RGBAColor(254, 222, 9, 1);
    self.superNavBarView.viewBottomLine.backgroundColor = RGBAColor(254, 222, 9, 1);
    /// 创建左侧按钮
    [self createNavLeftBtnWithItem:@""
                            target:self
                            action:@selector(btnClickBack:)];
    [self.superNavBarView.btnLeft setImage:[UIImage imageNamed:@"CommonBack"] forState:UIControlStateNormal];
}

- (void)initMainViews
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,
                                                                   TP_NavBar_H,
                                                                   screenW,
                                                                   screenH-TP_NavBar_H)
                                                  style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    [self.view addSubview:self.tableView];
    
    //
    self.viewHead = [[MeSettingHeadView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 44)];
    [self.viewHead setBtnTarget:self withLogoutAction:@selector(btnClickLogout:)];
    self.tableView.tableFooterView = self.viewHead;
}


#pragma mark - ********************** Functions **********************

#pragma mark - 注册消息

- (void)regNotification
{
    
}

#pragma mark - demo

- (void)demo
{
    
}


#pragma mark - ********************** Button Touch Event **********************

- (void)btnClickBack:(TPButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)btnClickLogout:(TPButton *)sender
{
    UIAlertView *alent = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您确定要退出么？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alent show];
}


#pragma mark - ********************** Net Connection Event **********************

#pragma mark - 请求 xxx

- (void)req_URL_xxx
{
    
}

#pragma mark - 处理 xxx

//- (void)reqSucc_URL_xxx:(TPRequest *)req
//{
//    
//}
//
//- (void)reqFail_URL_xxx:(TPRequest *)req
//{
//    
//}


#pragma mark - ********************** Delegate Event **********************

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MeSettingMainCell"];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MeSettingMainCell"];
    }
    
    if(indexPath.section == 0)
    {
        cell.textLabel.text = @"给我评分";
    }
    else
    {
        cell.textLabel.text = @"关于";
    }
    
    UIImage *img = [UIImage imageNamed:@"JianTou"];
    cell.accessoryView = [[UIImageView alloc] initWithImage:img];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if(indexPath.section == 0)
    {
        /*
        MPTLiveTestViewController *con = [MPTLiveTestViewController new];
        UINavigationController *navCon = [[UINavigationController alloc]initWithRootViewController:con];
        [self presentViewController:navCon animated:YES completion:nil];

        return;
        
        */
        
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/miao-pai-zhi-bo-zui-kuai-yu/id1047562725?mt=8"]];
    }
    else if(indexPath.section == 1)
    {
        MPTLiveAboutVC *vc = [[MPTLiveAboutVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
    switch (buttonIndex)
    {
        case 0:/// 点击取消
        {
            NSLog(@"Cancel Button Pressed");
            break;
        }
            
        default: /// 点击确定
        {
            [MPTLoginApp logout];
            AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
            [appDelegate AppFoution];
            break;
        }
    }
}

#pragma mark - ********************** Notification Event **********************

#pragma mark - 通知 xxx



@end
